#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import pytest
from utils.sign import get_sign
import json

@pytest.fixture(autouse=True)
def enter_subscribe_page_init_stocks(pyd,naviBar,get_auth_login_url,api):
    url=get_auth_login_url()
    r=pyd.visit(url).sleep().wait_for_request('/api/data/site/auth_login')

    token=json.loads(r.response.body)['result']['data']['token']
    apiPath = '/api/data/site/update_user_collect'
    defaultSubscribe=["000001", "000004", "000005", "605588", "300807","003005","301525","000333","000338","301517",
                      "300322", "300342", "600520", "688667", "603108","600326","300985","300603","688311","603110",
                      "300538"]
    # 添加默认订阅股票列表
    data = {
        "action": "update",
        "stock_code": defaultSubscribe
    }
    sign = get_sign(data)
    headers={
        'Signature':sign,
        'Authorization':'Bearer'+token
    }
    api.post(pyd.env['base_url'] + apiPath, json=data,headers=headers)
    pyd.find(naviBar.subscribeButton).click(force=True).sleep()
    yield
    # 用例执行完成 删除默认订阅股票列表
    data = {
        "action": "delete",
        "stock_code": defaultSubscribe
    }
    api.post(pyd.env['base_url'] + apiPath, json=data, headers=headers)


